package com.zoffy.oj_backend.model.vo;

import cn.hutool.json.JSONUtil;
import com.zoffy.oj_backend.model.dto.question.JudgeConfig;
import com.zoffy.oj_backend.model.entity.Question;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;

@Data
public class QuestionVo {
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 题目标签
     */
    private List<String> tags;

    /**
     * 题目提交数
     */
    private Integer submitNum;

    /**
     * 题目通过数
     */
    private Integer acceptedNum;

    /**
     * 判题设置
     */
    private JudgeConfig judgeConfig;

    private long userId;

    public static QuestionVo obj2Vo(Question question) {
        if (question == null) {
            return null;
        }
        QuestionVo questionVo = new QuestionVo();
        BeanUtils.copyProperties(question, questionVo);
        List<String> tags = JSONUtil.parseArray(question.getTags()).toList(String.class);

        questionVo.setTags(tags);
        JudgeConfig judgeConfig = JSONUtil.toBean(question.getJudgeConfig(), JudgeConfig.class);
        questionVo.setJudgeConfig(judgeConfig);
        return questionVo;
    }
}
